package com.ktgj.train.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.train.domain.TrainCountry;
import com.ktgj.train.service.ITrainCountryService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 国家Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@ControllerAdvice
@RestController
@RequestMapping("/country")
public class TrainCountryController extends BaseController
{
    @Autowired
    private ITrainCountryService trainCountryService;

    /**
     * 查询国家列表
     */
    @PreAuthorize(hasPermi = "train:country:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainCountry trainCountry)
    {
        startPage();
        List<TrainCountry> list = trainCountryService.selectTrainCountryList(trainCountry);
        return getDataTable(list);
    }

    /**
     * 导出国家列表
     */
    @PreAuthorize(hasPermi = "train:country:export")
    @Log(title = "国家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainCountry trainCountry) throws IOException
    {
        List<TrainCountry> list = trainCountryService.selectTrainCountryList(trainCountry);
        ExcelUtil<TrainCountry> util = new ExcelUtil<TrainCountry>(TrainCountry.class);
        util.exportExcel(response, list, "国家数据");
    }

    /**
     * 获取国家详细信息
     */
    @PreAuthorize(hasPermi = "train:country:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(trainCountryService.selectTrainCountryById(id));
    }

    /**
     * 新增国家
     */
    @PreAuthorize(hasPermi = "train:country:add")
    @Log(title = "国家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainCountry trainCountry)
    {
        return toAjax(trainCountryService.insertTrainCountry(trainCountry));
    }

    /**
     * 修改国家
     */
    @PreAuthorize(hasPermi = "train:country:edit")
    @Log(title = "国家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainCountry trainCountry)
    {
        return toAjax(trainCountryService.updateTrainCountry(trainCountry));
    }

    /**
     * 删除国家
     */
    @PreAuthorize(hasPermi = "train:country:remove")
    @Log(title = "国家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainCountryService.deleteTrainCountryByIds(ids));
    }
}
